package com.xoa.plugin.workflow.workflowservice.imlp.lnsfplugin;

import com.xoa.dev.efficiency.dao.FlowParaMapper;
import com.xoa.dev.efficiency.model.FlowAbilityMonitor;
import com.xoa.dev.efficiency.model.FlowPara;
import com.xoa.model.users.Users;
import com.xoa.plugin.workflow.workflowservice.WorkFlowService;
import com.xoa.util.SpringTool;
import com.xoa.util.ToJson;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class Save_1 implements WorkFlowService {
    @Override
    public ToJson run(HttpServletRequest request) {
        //先查询当前流程是否是重点流程
        String flowId = request.getParameter("flowId");
        Integer prcsId=Integer.parseInt(request.getParameter("prcsId"));
        String runId=request.getParameter("runId");
        Users user=LnsfUtil.init().getUser(request);
        FlowParaMapper flowParaMapper=(FlowParaMapper) SpringTool.getBean("flowParaMapper");
        FlowPara flowPara = flowParaMapper.selectInfo("FLOW_ID_F");
        if (flowPara != null) {
            if (flowPara.getParaValue().equals(flowId)) {
                //获取办理时限
                String outTime = LnsfUtil.init().getWorkDeadline(flowId, prcsId);
                //获取第一步办理记录
                Map<String, Object> map = new HashMap();
                map.put("runId", runId);
                map.put("prcsId", prcsId);
                map.put("userId", user.getUserId());
                String prcsTimes =  LnsfUtil.init().selectOnePrcsTime(map);
                if (prcsTimes != null) {
                    //装配值
                    FlowAbilityMonitor flowAbilityMonitor = new FlowAbilityMonitor();
                    flowAbilityMonitor.setRunId(Integer.parseInt(runId));
                    flowAbilityMonitor.setWorkDeadline(outTime);
                    flowAbilityMonitor.setUserId(user.getUserId());
                    flowAbilityMonitor.setDeptId(user.getDeptId() + "");
                    flowAbilityMonitor.setWorkType(1);
                    flowAbilityMonitor.setUserType(2);
                    flowAbilityMonitor.setDeptType(2);
                    flowAbilityMonitor.setWorkStart(prcsTimes);
                    String workTitle =  LnsfUtil.init().getWorkNameValue(flowId,runId,"工作事项");
                    if (workTitle == null) {
                        workTitle = "工作名称未定";
                    }
                    flowAbilityMonitor.setWorkTitle(workTitle);
                    LnsfUtil.init().setData(flowAbilityMonitor);
                }
            }else{
                //不是重点流程
            }
        }
        return null;
    }

}
